//
//  BangDViewController.m
//  day1
//
//  Created by 于跃隆 on 2020/4/9.
//  Copyright © 2020 于跃隆. All rights reserved.
//

#import "BangDViewController.h"
#import "LoginNumberViewController.h"

@interface BangDViewController ()

@end

@implementation BangDViewController

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    self.navigationController.navigationBar.hidden = NO;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setNavContorlFrame];
    self.navigationController.navigationBar.hidden = NO;
}
-(void)setNavContorlFrame{
    //设置导航条颜色
        UIView *Jbview = [[UIView alloc] init];
        Jbview.userInteractionEnabled = YES;
    //    Jbview.frame = CGRectMake(0,KSCHEIGHT(-37),kSCRATIO(self.view.frame.size.width),KSCHEIGHT(75));

        CAGradientLayer *gl = [CAGradientLayer layer];
        gl.frame = CGRectMake(0,KSCHEIGHT(0),kSCRATIO(self.view.frame.size.width),KSCHEIGHT(82));
        gl.startPoint = CGPointMake(0, 0);
        gl.endPoint = CGPointMake(1, 1);
        gl.colors = @[(__bridge id)[UIColor colorWithRed:247/255.0 green:65/255.0 blue:91/255.0 alpha:1.0].CGColor,(__bridge id)[UIColor colorWithRed:251/255.0 green:171/255.0 blue:102/255.0 alpha:1.0].CGColor];
        gl.locations = @[@(0.0),@(1.0)];
        [Jbview.layer addSublayer:gl];
        
        [self.navigationController.navigationBar addSubview:Jbview];
        
        //返回button
        UIButton *backBtn = [[UIButton alloc] init];
        [backBtn setBackgroundImage:[UIImage imageNamed:@"backButton"] forState:UIControlStateNormal];
        [backBtn addTarget:self action:@selector(BackClick) forControlEvents:UIControlEventTouchUpInside];
        [Jbview addSubview:backBtn];
        
        //标题文字
        UILabel *navtitle = [[UILabel alloc] init];
        navtitle.text = @"绑定信息";
        navtitle.textColor = [UIColor whiteColor];
        navtitle.font = kFONT(18);
        [Jbview addSubview:navtitle];
        
        [Jbview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(KSCHEIGHT(-37));
            make.width.mas_equalTo(kSCRATIO(self.view.frame.size.width));
            make.height.mas_equalTo(KSCHEIGHT(82));
        }];
        [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(Jbview.mas_left).mas_equalTo(kSCRATIO(20));
            make.bottom.mas_equalTo(Jbview.bottom).mas_equalTo(KSCHEIGHT(-15));
            make.width.mas_equalTo(kSCRATIO(10));
            make.height.mas_equalTo(KSCHEIGHT(18));
        }];
        [navtitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(Jbview);
            make.bottom.mas_equalTo(Jbview.bottom).mas_equalTo(KSCHEIGHT(-12));
            
        }];
}
-(void)BackClick{
    [self.navigationController popViewControllerAnimated:NO];
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.navigationItem setHidesBackButton:YES];
    [self.navigationController.navigationItem setHidesBackButton:YES];
    [self.navigationController.navigationBar.backItem setHidesBackButton:YES];
    
    
    //245 246 251
    self.view.backgroundColor = [UIColor colorWithRed:245/255.0 green:246/255.0 blue:251/255.0 alpha:1.0];
    
    
    UserModel *user = [UserModel sharedInstance:UserKey0];
    
    
    if (user.isLogin == YES) {
        
        //已绑定页面
        [self setBdTureFrame];
        
        
    }else{
        
        //未绑定页面
        [self setBdFailFrame];
        
    }
    
    
}
//成功
-(void)setBdTureFrame{
    UIView *whiteView = [[UIView alloc] init];
    whiteView.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
    [self.view addSubview:whiteView];
    
    [whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(KSCHEIGHT(15));
        make.width.mas_equalTo(kSCRATIO(self.view.frame.size.width));
        make.height.mas_equalTo(KSCHEIGHT(50));
    }];
    
    UILabel *bangDlabel = [[UILabel alloc] init];
    bangDlabel.numberOfLines = 0;
    bangDlabel.text = @"绑定手机号码";
    bangDlabel.font = [UIFont fontWithName:@"Microsoft YaHei" size:kSCRATIO(15)];
    bangDlabel.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
    [self.view addSubview:bangDlabel];
    
    [bangDlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(whiteView);
        make.left.mas_equalTo(whiteView.mas_left).mas_equalTo(kSCRATIO(30));
        
    }];
    
    UILabel *numbeRlabel = [[UILabel alloc] init];
    UserModel *user = [UserModel sharedInstance:UserKey0];
    NSLog(@"%@",user.token);
    numbeRlabel.numberOfLines = 0;
    numbeRlabel.text = user.mobile;
    numbeRlabel.font = [UIFont fontWithName:@"Microsoft YaHei" size:kSCRATIO(15)];
    numbeRlabel.textColor = [UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1.0];
    [self.view addSubview:numbeRlabel];
    
    [numbeRlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(whiteView);
        make.right.mas_equalTo(whiteView.mas_right).mas_equalTo(kSCRATIO(-30));
        
    }];
    
    
}
//不成功
-(void)setBdFailFrame{
    UIView *whiteFaView = [[UIView alloc] init];
    whiteFaView.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
    [self.view addSubview:whiteFaView];
    
    [whiteFaView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(KSCHEIGHT(15));
        make.width.mas_equalTo(kSCRATIO(self.view.frame.size.width));
        make.height.mas_equalTo(KSCHEIGHT(50));
    }];
    
    UILabel *bangWxlabel = [[UILabel alloc] init];
    bangWxlabel.numberOfLines = 0;
    bangWxlabel.text = @"绑定微信";
    bangWxlabel.font = [UIFont fontWithName:@"Microsoft YaHei" size:kSCRATIO(15)];
    bangWxlabel.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
    [self.view addSubview:bangWxlabel];
    
    [bangWxlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(whiteFaView);
        make.left.mas_equalTo(whiteFaView.mas_left).mas_equalTo(kSCRATIO(30));
        
    }];
    
    UIView *whiteFaViewT = [[UIView alloc] init];
    whiteFaViewT.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
    [self.view addSubview:whiteFaViewT];
    
    [whiteFaViewT mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(whiteFaView.mas_bottom).mas_equalTo(KSCHEIGHT(5));
        make.width.mas_equalTo(kSCRATIO(self.view.frame.size.width));
        make.height.mas_equalTo(KSCHEIGHT(50));
    }];
    
    UILabel *bangNumlabel = [[UILabel alloc] init];
    bangNumlabel.numberOfLines = 0;
    bangNumlabel.text = @"绑定手机号";
    bangNumlabel.font = [UIFont fontWithName:@"Microsoft YaHei" size:kSCRATIO(15)];
    bangNumlabel.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
    [self.view addSubview:bangNumlabel];
    
    [bangNumlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(whiteFaViewT);
        make.left.mas_equalTo(whiteFaViewT.mas_left).mas_equalTo(kSCRATIO(30));
        
    }];
    
    //微信绑定按钮
    UIButton *wxBBtn  = [UIButton CreatButtontext:@"去绑定" image:nil Font:[UIFont fontWithName:@"Helvetica-Bold" size:kSCRATIO(14)] Textcolor:ColorWhite];
    [wxBBtn addTarget:self action:@selector(wxBnClick:) forControlEvents:UIControlEventTouchUpInside];
    wxBBtn.backgroundColor = [UIColor colorWithRed:248/255.0 green:80/255.0 blue:92/255.0 alpha:1.0];
    wxBBtn.layer.shadowColor = [UIColor colorWithRed:173/255.0 green:172/255.0 blue:172/255.0 alpha:0.14].CGColor;
    ViewRadius(wxBBtn, KSCHEIGHT(15));
    [whiteFaView addSubview:wxBBtn];
    
    [wxBBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(whiteFaView);
        make.right.mas_equalTo(whiteFaView.mas_right).mas_equalTo(kSCRATIO(-20));
        make.width.mas_equalTo(kSCRATIO(100));
        make.height.mas_equalTo(KSCHEIGHT(30));
        
    }];
    
    //手机号绑定绑定按钮
    UIButton *numbeRBtn  = [UIButton CreatButtontext:@"去绑定" image:nil Font:[UIFont fontWithName:@"Helvetica-Bold" size:kSCRATIO(14)] Textcolor:ColorWhite];
    [numbeRBtn addTarget:self action:@selector(numberClick:) forControlEvents:UIControlEventTouchUpInside];
    numbeRBtn.backgroundColor = [UIColor colorWithRed:248/255.0 green:80/255.0 blue:92/255.0 alpha:1.0];
    numbeRBtn.layer.shadowColor = [UIColor colorWithRed:173/255.0 green:172/255.0 blue:172/255.0 alpha:0.14].CGColor;
    ViewRadius(numbeRBtn, KSCHEIGHT(15));
    [whiteFaViewT addSubview:numbeRBtn];
    
    [numbeRBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(whiteFaViewT);
        make.right.mas_equalTo(whiteFaViewT.mas_right).mas_equalTo(kSCRATIO(-20));
        make.width.mas_equalTo(kSCRATIO(100));
        make.height.mas_equalTo(KSCHEIGHT(30));
        
    }];
    
    
}
//微信绑定跳转事件
-(void)wxBnClick:(UIButton *)btn{
    
}
//手机号绑定跳转
-(void)numberClick:(UIButton *)btn{
    LoginNumberViewController *loginC = [[LoginNumberViewController alloc] init];
    loginC.modalPresentationStyle = 0;
    [self presentViewController:loginC animated:NO completion:^{
        
    }];
}





@end
